home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / curve.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.1 KB  |  114 lines

  1. //
  2. // "$Id: curve.cxx,v 1.4 1999/01/07 19:17:52 mike Exp $"
  3. //
  4. // Curve test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Double_Window.H>
  28. #include <FL/Fl_Hor_Value_Slider.H>
  29. #include <FL/fl_draw.H>
  30. #include <FL/Fl_Toggle_Button.H>
  31.  
  32. double args[9] = {
  33.   20,20, 50,200, 100,20, 200,200, 0};
  34. const char* name[9] = {
  35.   "X0", "Y0", "X1", "Y1", "X2", "Y2", "X3", "Y3", "rotate"};
  36.  
  37. int points;
  38.  
  39. class Drawing : public Fl_Widget {
  40.   void draw() {
  41.     fl_clip(x(),y(),w(),h());
  42.     fl_color(FL_DARK3);
  43.     fl_rectf(x(),y(),w(),h());
  44.     fl_push_matrix();
  45.     if (args[8]) {
  46.       fl_translate(x()+w()/2.0, y()+h()/2.0);
  47.       fl_rotate(args[8]);
  48.       fl_translate(-(x()+w()/2.0), -(y()+h()/2.0));
  49.     }
  50.     fl_translate(x(),y());
  51.     if (!points) {
  52.     fl_color(FL_WHITE);
  53.     fl_begin_complex_polygon();
  54.    fl_curve(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
  55.     fl_end_complex_polygon();
  56.     }
  57.     fl_color(FL_BLACK);
  58.     fl_begin_line();
  59.     fl_vertex(args[0],args[1]);
  60.     fl_vertex(args[2],args[3]);
  61.     fl_vertex(args[4],args[5]);
  62.     fl_vertex(args[6],args[7]);
  63.     fl_end_line();
  64.     fl_color(points ? FL_WHITE : FL_RED);
  65.     points ? fl_begin_points() : fl_begin_line();
  66.    fl_curve(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
  67.     points ? fl_end_points() : fl_end_line();
  68.     fl_pop_matrix();
  69.     fl_pop_clip();
  70.   }
  71. public:
  72.   Drawing(int X,int Y,int W,int H) : Fl_Widget(X,Y,W,H) {}
  73. };
  74.  
  75. Drawing *d;
  76.  
  77. void points_cb(Fl_Widget* o, void*) {
  78.   points = ((Fl_Toggle_Button*)o)->value();
  79.   d->redraw();
  80. }
  81.  
  82. void slider_cb(Fl_Widget* o, void* v) {
  83.   Fl_Slider* s = (Fl_Slider*)o;
  84.   args[long(v)] = s->value();
  85.   d->redraw();
  86. }
  87.  
  88. int main(int argc, char** argv) {
  89.   Fl_Double_Window window(300,555);
  90.   Drawing drawing(10,10,280,280);
  91.   d = &drawing;
  92.  
  93.   int y = 300;
  94.   for (int n = 0; n<9; n++) {
  95.     Fl_Slider* s = new Fl_Hor_Value_Slider(50,y,240,25,name[n]); y += 25;
  96.     s->minimum(0); s->maximum(280);
  97.     if (n == 8) s->maximum(360);
  98.     s->step(1);
  99.     s->value(args[n]);
  100.     s->align(FL_ALIGN_LEFT);
  101.     s->callback(slider_cb, (void*)n);
  102.   }
  103.   Fl_Toggle_Button but(50,y,50,25,"points");
  104.   but.callback(points_cb);
  105.  
  106.   window.end();
  107.   window.show(argc,argv);
  108.   return Fl::run();
  109. }
  110.  
  111. //
  112. // End of "$Id: curve.cxx,v 1.4 1999/01/07 19:17:52 mike Exp $".
  113. //
  114.